home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / misc / emu / p-interp.lha / p-interp-0.4 / Stack.c < prev    next >
C/C++ Source or Header  |  2001-05-20  |  2KB  |  80 lines

  1. /*
  2.  
  3.   P-Code interpreter (to run the apple pascal system)
  4.   Copyright (C) 2000 Mario Klebsch
  5.  
  6.   This program is free software; you can redistribute it and/or modify
  7.   it under the terms of the GNU General Public License as published by
  8.   the Free Software Foundation; either version 2 of the License, or
  9.   (at your option) any later version.
  10.  
  11.   This program is distributed in the hope that it will be useful,
  12.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.   GNU General Public License for more details.
  15.  
  16.   You should have received a copy of the GNU General Public License
  17.   along with this program; if not, write to the Free Software
  18.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20.   $Log: Stack.c,v $
  21.   Revision 1.2  2001/05/20 13:12:02  mario
  22.   CVS-Idents und Logs eingefügt
  23.  
  24.  
  25. */
  26.  
  27. #ident "$Id: Stack.c,v 1.2 2001/05/20 13:12:02 mario Exp $";
  28.  
  29. #include <stdio.h>
  30. #include <assert.h>
  31.  
  32. #include "psystem.h"
  33. #include "Memory.h"
  34. #include "Stack.h"
  35.  
  36. extern word Sp;
  37.  
  38. word Pop(void)
  39. {
  40.   word    ret=MemRd(Sp);
  41.   Sp = WordIndexed(Sp, 1);
  42.   if (Sp>SP_TOP)
  43.     panic("Stack underflow");
  44.   return(ret);
  45. }
  46.  
  47. Integer PopInteger(void)
  48. {
  49.   word w=Pop();
  50.  
  51.   if (w&0x8000)
  52.     return(w-0x10000);
  53.   else
  54.     return(w);
  55. }
  56.  
  57. float PopReal(void)
  58. {
  59.   word Buffer[2];
  60.  
  61.   assert (sizeof(word)==2);
  62.   Buffer[0]=Pop();
  63.   Buffer[1]=Pop();
  64.   return(*(float*)Buffer);
  65. }
  66.  
  67. void Push(word Value)
  68. {
  69.   Sp = WordIndexed(Sp, -1);
  70.   MemWr(Sp, Value);
  71. }
  72.  
  73. void PushReal(float Value)
  74. {
  75.   word    *Buffer=(word*)&Value;
  76.   assert (sizeof(word)==2);
  77.   Push(Buffer[1]);
  78.   Push(Buffer[0]);
  79. }
  80.